﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Arizu.Repository;
using System.Data;

namespace AiRiZu.User
{
    
    public partial class Comments : Common
    {
        public string ByYou = "";
        public string ToYou = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["logId"] == null)
            {
                return;
            }

            AirizuComments airizuComments = AirizuComments.CreateInstance();
            AirizuUser airizuUser = AirizuUser.CreateInstance();

            DataTable dt1 = airizuComments.GetCommentByCreator(int.Parse(Session["logId"].ToString()));

            if (dt1.Rows.Count > 0)
            {
                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    ByYou += "给 " + GetUserName(airizuUser, int.Parse(dt1.Rows[i]["Reciver"].ToString())) + " 的评价: <p>" + dt1.Rows[i]["Comment"].ToString() + "<p>";
                }
            }
            else
            {
                ByYou = "您暂时还没有给别人评价";
            }


            DataTable dt2 = airizuComments.GetCommentByReciver(int.Parse(Session["logId"].ToString()));

            if (dt2.Rows.Count > 0)
            {
                for (int i = 0; i < dt2.Rows.Count; i++)
                {
                    ToYou += GetUserName(airizuUser, int.Parse(dt2.Rows[i]["Creator"].ToString())) + " 给你的评价: <p>" + dt2.Rows[i]["Comment"].ToString() + "<p>";
                }
            }
            else
            {
                ToYou = "暂时还没有人给您评价";
            }
        }

        private string GetUserName(AirizuUser airizuUser, int userId)
        {
            string res = "";
            try
            {
                DataTable dt2 = airizuUser.GetUser(userId);
                if (dt2.Rows.Count > 0)
                {
                    res = dt2.Rows[0]["Xing"].ToString() + " " + dt2.Rows[0]["Ming"].ToString();
                }
            }
            catch (Exception)
            {
                
                throw;
            }
            
            return res;
        }
    }
}
